package com.example.eurekaclient_provider1.controller;

import com.example.eurekaclient_provider1.domain.R;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * ClassName:ProviderController
 * Package:com.bjpowernode.springcloud.controller
 * Description: 描述信息
 *
 * @date:2021/12/17 16:36
 * @author:动力节点
 */
@RestController
@RequestMapping("/provider")
public class ProviderController {

    /*
        远程访问的参数发送的方式
            http://localhost:7001/provider/01
                这种方式，直接接收即可
            http://localhost:7001/provider/01/{id}/{username}
                通过地址栏参数，进行封装
            http://localhost:7001/provider/01/{id}/{username}?age=18&desc=我是张三
                通过地址栏传递键值对参数
            http://localhost:7001/provider/01/{id}/{username}?age=18&desc=我是张三
                将部分参数，封装到了请求体当中
        远程访问的参数的接收方式
            http://localhost:7001/provider/01/{id}/{username}
                通过注解进行接收，@PathVariable(name="id")
            http://localhost:7001/provider/01/{id}/{username}?age=18&desc=我是张三
                通过注解进行接收，@PathVariable(name="id")
                通过注解接收键值对的参数，@RequestParams(name="age")
            http://localhost:7001/provider/01/{id}/{username}?age=18&desc=我是张三
                通过注解进行接收，@PathVariable(name="id")
                通过注解接收键值对的参数，@RequestParams(name="age")
                通过注解接收请求体中的数据，@RequestBody
     */

    @GetMapping("/01")
    public R provider01(){
        // int i=1/0;
        return R.ok(0,"远程调用成功...");
    }

    @GetMapping("/02/{id}/{username}")
    public R provider02(@PathVariable Integer id,@PathVariable(name = "username") String username){

        Map<String,Object> providerData = new HashMap<>();
        providerData.put("id",id);
        providerData.put("username",username);

        return R.ok(0,"远程调用成功...",providerData);
    }

    @GetMapping("/03/{id}/{username}")
    public R provider03(@PathVariable Integer id, @PathVariable String username,
                        @RequestParam String age, @RequestParam String desc){

        Map<String,Object> providerData = new HashMap<>();
        providerData.put("id",id);
        providerData.put("username",username);
        providerData.put("age",age);
        providerData.put("desc",desc);

        return R.ok(0,"远程调用成功...",providerData);
    }

    @PostMapping("/04/{id}/{username}")
    public R provider04(@PathVariable Integer id,
                        @PathVariable String username,
                        @RequestParam String age,
                        @RequestParam String desc,
                        @RequestBody  Map<String,Object> requestBody){

        Map<String,Object> providerData = new HashMap<>();
        providerData.put("id",id);
        providerData.put("username",username);
        providerData.put("age",age);
        providerData.put("desc",desc);
        providerData.put("requestBody",requestBody);

        return R.ok(0,"远程调用成功...",providerData);

    }

    @PostMapping("/05/{id}/{username}")
    public R provider05(@PathVariable Integer id,
                        @PathVariable String username,
                        @RequestParam String age,
                        @RequestParam String desc,
                        @RequestBody  Map<String,Object> requestBody){

        Map<String,Object> providerData = new HashMap<>();
        providerData.put("id",id);
        providerData.put("username",username);
        providerData.put("age",age);
        providerData.put("desc",desc);
        providerData.put("requestBody",requestBody);

        return R.ok(0,"远程调用成功...",providerData);
    }

    @PutMapping("/06/{id}/{username}")
    public R provider06(@PathVariable Integer id,
                        @PathVariable String username,
                        @RequestParam String age,
                        @RequestParam String desc,
                        @RequestBody  Map<String,Object> requestBody){

        Map<String,Object> providerData = new HashMap<>();
        providerData.put("id",id);
        providerData.put("username",username);
        providerData.put("age",age);
        providerData.put("desc",desc);
        providerData.put("requestBody",requestBody);

        System.out.println("id :::>>> "+id);
        System.out.println("username :::>>> "+username);
        System.out.println("age :::>>> "+age);
        System.out.println("desc :::>>> "+desc);
        System.out.println("requestBody :::>>> "+requestBody);

        return R.ok(0,"远程调用成功...",providerData);
    }


    @DeleteMapping("/07/{id}/{username}")
    public R provider07(@PathVariable Integer id, @PathVariable String username,
                        @RequestParam String age, @RequestParam String desc){

        Map<String,Object> providerData = new HashMap<>();
        providerData.put("id",id);
        providerData.put("username",username);
        providerData.put("age",age);
        providerData.put("desc",desc);

        System.out.println("id :::>>> "+id);
        System.out.println("username :::>>> "+username);
        System.out.println("age :::>>> "+age);
        System.out.println("desc :::>>> "+desc);

        return R.ok(0,"远程调用成功...",providerData);
    }
}
